home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / pyatspi / event.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  8.5 KB  |  231 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''
  5. Wrapper classes for AT-SPI events and device events.
  6.  
  7. @author: Peter Parente
  8. @organization: IBM Corporation
  9. @copyright: Copyright (c) 2005, 2007 IBM Corporation
  10. @license: LGPL
  11.  
  12. This library is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU Library General Public
  14. License as published by the Free Software Foundation; either
  15. version 2 of the License, or (at your option) any later version.
  16.  
  17. This library is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20. Library General Public License for more details.
  21.  
  22. You should have received a copy of the GNU Library General Public
  23. License along with this library; if not, write to the
  24. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25. Boston, MA 02111-1307, USA.
  26.  
  27. Portions of this code originally licensed and copyright (c) 2005, 2007
  28. IBM Corporation under the BSD license, available at
  29. U{http://www.opensource.org/licenses/bsd-license.php}
  30. '''
  31. import constants
  32.  
  33. class DeviceEvent(object):
  34.     '''
  35.   Wraps an AT-SPI device event with a more Pythonic interface. Primarily adds
  36.   a consume attribute which can be used to cease propagation of a device event.
  37.   
  38.   @ivar consume: Should this event be consumed and not allowed to pass on to
  39.     observers further down the dispatch chain in this process or possibly
  40.     system wide?
  41.   @type consume: boolean
  42.   @ivar type: Kind of event, KEY_PRESSED_EVENT or KEY_RELEASED_EVENT
  43.   @type type: Accessibility.EventType
  44.   @ivar id: Serial identifier for this key event
  45.   @type id: integer
  46.   @ivar hw_code: Hardware scan code for the key
  47.   @type hw_code: integer
  48.   @ivar modifiers: Modifiers held at the time of the key event
  49.   @type modifiers: integer
  50.   @ivar timestamp: Time at which the event occurred relative to some platform
  51.     dependent starting point (e.g. XWindows start time)
  52.   @type timestamp: integer
  53.   @ivar event_string: String describing the key pressed (e.g. keysym)
  54.   @type event_string: string
  55.   @ivar is_text: Is the event representative of text to be inserted (True), or 
  56.     of a control key (False)?
  57.   @type is_text: boolean
  58.   '''
  59.     
  60.     def __init__(self, event):
  61.         '''
  62.     Attaches event data to this object.
  63.     
  64.     @param event: Event object
  65.     @type event: Accessibility.DeviceEvent
  66.     '''
  67.         self.consume = False
  68.         self.type = event.type
  69.         self.id = event.id
  70.         self.hw_code = event.hw_code
  71.         self.modifiers = event.modifiers
  72.         self.timestamp = event.timestamp
  73.         self.event_string = event.event_string
  74.         self.is_text = event.is_text
  75.  
  76.     
  77.     def __str__(self):
  78.         '''
  79.     Builds a human readable representation of the event.
  80.  
  81.     @return: Event description
  82.     @rtype: string
  83.     '''
  84.         if self.type == constants.KEY_PRESSED_EVENT:
  85.             kind = 'pressed'
  86.         elif self.type == constants.KEY_RELEASED_EVENT:
  87.             kind = 'released'
  88.         
  89.         return '%s\n\thw_code: %d\n\tevent_string: %s\n\tmodifiers: %d\n\tid: %d\n\ttimestamp: %d\n\tis_text: %s' % (kind, self.hw_code, self.event_string, self.modifiers, self.id, self.timestamp, self.is_text)
  90.  
  91.  
  92.  
  93. class Event(object):
  94.     '''
  95.   Wraps an AT-SPI event with a more Pythonic interface managing exceptions,
  96.   the differences in any_data across versions, and the reference counting of
  97.   accessibles provided with the event.
  98.   
  99.   @note: All unmarked attributes of this class should be considered public
  100.     readable and writable as the class is acting as a record object.
  101.     
  102.   @ivar consume: Should this event be consumed and not allowed to pass on to
  103.     observers further down the dispatch chain in this process?
  104.   @type consume: boolean
  105.   @ivar type: The type of the AT-SPI event
  106.   @type type: L{EventType}
  107.   @ivar detail1: First AT-SPI event parameter
  108.   @type detail1: integer
  109.   @ivar detail2: Second AT-SPI event parameter
  110.   @type detail2: integer
  111.   @ivar any_data: Extra AT-SPI data payload
  112.   @type any_data: object
  113.   @ivar host_application: Application owning the event source
  114.   @type host_application: Accessibility.Application
  115.   @ivar source_name: Name of the event source at the time of event dispatch
  116.   @type source_name: string
  117.   @ivar source_role: Role of the event source at the time of event dispatch
  118.   @type source_role: Accessibility.Role
  119.   @ivar source: Source of the event
  120.   @type source: Accessibility.Accessible
  121.   '''
  122.     
  123.     def __init__(self, event):
  124.         '''
  125.     Extracts information from the provided event. If the event is a "normal" 
  126.     event, pulls the detail1, detail2, any_data, and source values out of the
  127.     given object and stores it in this object. If the event is a device event,
  128.     key ID is stored in detail1, scan code is stored in detail2, key name, 
  129.     key modifiers (e.g. ALT, CTRL, etc.), is text flag, and timestamp are 
  130.     stored as a 4-tuple in any_data, and source is None (since key events are
  131.     global).
  132.  
  133.     @param event: Event from an AT-SPI callback
  134.     @type event: Accessibility.Event or Accessibility.DeviceEvent
  135.     '''
  136.         self.consume = False
  137.         self.type = EventType(event.type)
  138.         self.detail1 = event.detail1
  139.         self.detail2 = event.detail2
  140.         
  141.         try:
  142.             event.source.ref()
  143.         except AttributeError:
  144.             pass
  145.  
  146.         self.source = event.source
  147.         details = event.any_data.value()
  148.         
  149.         try:
  150.             self.any_data = details.any_data.value()
  151.         except Exception:
  152.             self.any_data = details
  153.             self.host_application = None
  154.             self.source_name = None
  155.             self.source_role = None
  156.  
  157.         self.host_application = details.host_application
  158.         self.source_name = details.source_name
  159.         self.source_role = details.source_role
  160.         
  161.         try:
  162.             self.any_data.ref()
  163.         except AttributeError:
  164.             pass
  165.  
  166.         
  167.         try:
  168.             self.host_application.ref()
  169.         except AttributeError:
  170.             pass
  171.  
  172.  
  173.     
  174.     def __str__(self):
  175.         '''
  176.     Builds a human readable representation of the event including event type,
  177.     parameters, and source info.
  178.  
  179.     @return: Event description
  180.     @rtype: string
  181.     '''
  182.         return '%s(%s, %s, %s)\n\tsource: %s\n\thost_application: %s' % (self.type, self.detail1, self.detail2, self.any_data, self.source, self.host_application)
  183.  
  184.  
  185.  
  186. class EventType(str):
  187.     """
  188.   Wraps the AT-SPI event type string so its components can be accessed 
  189.   individually as klass (can't use the keyword class), major, minor, and detail 
  190.   (klass:major:minor:detail).
  191.   
  192.   @note: All attributes of an instance of this class should be considered 
  193.     public readable as it is acting a a struct.
  194.   @ivar klass: Most general event type identifier (object, window, mouse, etc.)
  195.   @type klass: string
  196.   @ivar major: Second level event type description
  197.   @type major: string
  198.   @ivar minor: Third level event type description
  199.   @type minor: string
  200.   @ivar detail: Lowest level event type description
  201.   @type detail: string
  202.   @ivar name: Full, unparsed event name as received from AT-SPI
  203.   @type name: string
  204.   @cvar format: Names of the event string components
  205.   @type format: 4-tuple of string
  206.   """
  207.     format = ('klass', 'major', 'minor', 'detail')
  208.     
  209.     def __init__(self, name):
  210.         '''    
  211.     Parses the full AT-SPI event name into its components
  212.     (klass:major:minor:detail). If the provided event name is an integer
  213.     instead of a string, then the event is really a device event.
  214.     
  215.     @param name: Full AT-SPI event name
  216.     @type name: string
  217.     @raise AttributeError: When the given event name is not a valid string 
  218.     '''
  219.         self.value = name.strip(':')
  220.         self.name = self.value
  221.         self.klass = None
  222.         self.major = None
  223.         self.minor = None
  224.         self.detail = None
  225.         split = self.value.split(':', 3)
  226.         for i in xrange(len(split)):
  227.             setattr(self, self.format[i], split[i])
  228.         
  229.  
  230.  
  231.